import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {MenuInfo, MenuQuery, MenuForm} from "./types";


/**
 * 获取分页列表
 *
 * @param queryParams
 */
export function fetchList(
  queryParams: MenuQuery
): AxiosPromise<PageResult<MenuInfo[]>> {
  return request({
    url: "/admin/wechatMenu/getData",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取一级菜单
 *
 * @param ids
 */
export function getSelectData(): AxiosPromise<OptionType> {
  return request({
    url: "/admin/wechatMenu/getSelectData",
    method: "get"
  });
}

/**
 * 获取表单详情
 *
 * @param ids
 */
export function getMenuForm(ids: number): AxiosPromise<MenuForm> {
  return request({
    url: "/admin/wechatMenu/edit",
    method: "get",
    params: {
      ids: ids,
    },
  });
}

/**
 * 添加
 *
 * @param data
 */
export function addMenu(data: any) {
  return request({
    url: "/admin/wechatMenu/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改
 *
 * @param id
 * @param data
 */
export function updateMenu(id: number, data: MenuForm) {
  return request({
    url: "/admin/wechatMenu/edit",
    method: "put",
    data: data,
  });
}

/**
 * 同步数据
 */
export function syncData() {
  return request({
    url: "/admin/wechatMenu/syncData",
    method: "patch",
  });
}

/**
 * 删除
 *
 * @param data
 */
export function deleteMenu(data: any) {
  return request({
    url: "/admin/wechatMenu/del",
    method: "delete",
    data,
  });
}
